// * 成本管理模块table字段
import { toThousands } from "@/utils/numberFormat"
import { settleStatus, approvalStatus, settleDetailStatus } from './status'
// * 结算汇总table字段
export const rollupTableColumn = [
  {
    name: "一级部门名称",
    value: "deptName",
    width: '110px',
  },
  {
    name: "外包人数",
    value: "people",
  },
  {
    name: "结算月度",
    value: "monthly",
  },
  {
    name: "发票信息",
    width: '220px',
    render: (h, { row, listeners }) => {
      let imgArr = []
      const splitFile = row.invoiceList || []
      if(splitFile.length){
        splitFile.map(i => {
          const url = i.split('?')[0]
          console.log(url)
          let len = url.length
          let fileType = url.lastIndexOf('.pdf')
          let isPDF = len - (fileType + 4)
          imgArr.push(isPDF === 0 ? h('img', {
            class: 'td-pdf-icon',
            attrs: {
              src: require("../../../assets/images/pdf.png"),
              height: '24',
              width: '40'
            },
            on: {
              click: () => {
                listeners.click({eventName: 'onPreview', file:`${window.location.protocol}//${window.location.hostname}/${i}`})
              }
            }
          }, null) : h('img', {
            attrs: {
              src: `${window.location.protocol}//${window.location.hostname}/${i}`,
              width: '40px',
              height: '30px'
            },
            on: {
              click: () => {
                listeners.click({eventName: 'onPreview', file:`${window.location.protocol}//${window.location.hostname}/${i}`})
              }
            }
          }))
        })
      }else{
        imgArr.push(h('span', null, '--'))
      }

      return h('div', {
        class: 'image-group-box'
      }, imgArr, null)
    }
  },
  {
    name: "结算单生成进度",
    slot: "plan",
    width: '130px'
  },
  {
    name: "结算状态",
    render: (h, { row }) => {
      return h('span', {
        class: settleStatus[row.settleState] ? settleStatus[row.settleState].className : ''
      } , [
        h('span', {
          class: 'circle'
        }, null),
        h('span', null, settleStatus[row.settleState] ? settleStatus[row.settleState].label : '')
      ])
    }
  },
  {
    name: "审批状态",
    render: (h, { row }) => {
      return h('span', {
        class: approvalStatus[row.flowState] ? approvalStatus[row.flowState].className : '',
      } , [
        h('span', {
          class: 'circle'
        }, null),
        h('span', null, approvalStatus[row.flowState] ? approvalStatus[row.flowState].label : '')
      ])
    }
  },
  // {
  //   name: "驳回原因",
  //   render: (h, { row, listeners }) => {
  //     return h('span', {
  //       class: ' table-btn font-color-blue',
  //       on: {
  //         click: function () {
  //           listeners.click('onRejectDetail')
  //         }
  //       }
  //     }, '详情')
  //   }
  // },
  {
    name: "操作",
    type: "operate",
    width: "190px",
    fixed: "right",
    render: (h, { row, listeners }) => {
      return h('div', {
        class: 'table-btn-group'
      }, [
        // * 结算单下载-前置条件-row.invoiceState ===2的时候可以下载发票（数据已审批并且已推送成功至财务中台）
        row.invoiceState === 2 ? h('span', {
          class: `cursor table-btn color-pink`,
          on: {
            click: function () {
              listeners.click('onDown')
            }
          }
        }, '结算单下载') : null,
        h('span', {
          class: `cursor table-btn table-blue-btn `,
          on: {
            click: function () {
              listeners.click('onLookDetail')
            }
          }
        }, '查看')
      ], null);
    },
  },
]

// * 结算汇总明细table字段
export const userRollupHeaderItems = [
  {
    name: "员工姓名",
    value: "userName",
    fixed: "left",
  },
  {
    name: "员工编号",
    value: "userNo",
    fixed: "left",
  },
  {
    name: "岗位名称",
    value: "positionName",
    fixed: "left",
  },
  {
    name: "岗位职级",
    value: "rankLevelName",
  },
  {
    name: "所在部门",
    value: "deptName",
    width: "140px",
  },
  {
    name: "成本中心",
    value: "costCenterCode",
  },
  {
    name: "结算方式",
    value: "settleMethod",
    width: "100px",
  },
  {
    name: "结算月度",
    value: "monthly",
  },
  {
    name: "总工时(月)",
    value: "workHours",
    width: "100px",
  },
  {
    name: "结算费用",
    value: "needsCode",
    fixed: "right",
    render: (h, { row }) => {
      return h('span', {
        class: settleStatus[row.settleState] ? settleStatus[row.settleState].className : ''
      } , [
        h('span', {
          class: 'circle'
        }, null),
        h('span', null, settleStatus[row.settleState] ? settleStatus[row.settleState].detailLable : '--')
      ])
    }
  },
  {
    name: "审批状态",
    value: "needsCode",
    fixed: "right",
    slot: 'approval'
  },
  {
    name: "操作",
    width: '150px',
    fixed: "right",
    render: (h, { row, listeners }) => {
      return h('div', {}, [
        h('span', {
          class: `cursor table-btn table-blue-btn `,
          on: {
            click: function () {
              listeners.click('onLookDetail')
            }
          }
        }, '查看'),
        row.remind === 1? h(
          "span",
          {
            class: "cursor table-btn table-blue-btn",
            on: {
              click: function () {
                listeners.click("onRemind");
              },
            },
          },
          "结算审批提醒"
        ): '',
      ])
    }
  }

]

// * 费用明细人员详情审批节点
export const userRollupDetailApprovalItem = [
  {
    name: "审批人",
    value: "operator",
  },
  {
    name: "审批时间",
    value: "createDate",
  },
  {
    name: "审批状态",
    render: (h, { row }) => {
      return h('span', {
        class: settleDetailStatus[row.flowState] ? settleDetailStatus[row.flowState].className : ''
      } , [
        h('span', {
          class: 'circle'
        }, null),
        h('span', null, settleDetailStatus[row.flowState] ? settleDetailStatus[row.flowState].label : '')
      ])
    }
  },
  {
    name: "驳回意见",
    slot: 'comment'
  },
]

// * 一键结算列表table字段
export const settlementTableHeaderItems = [
  {
    name: "部门名称",
    value: "deptName",
  },
  {
    name: "成本中心",
    value: "deptName",
  },
  {
    name: "外包人数",
    value: "numberPeople",
  },
  {
    name: "结算费用",
    render: (h, { row }) => {
      return h('span', null, toThousands(row.settleCost))
    }
  },
]

// * 考勤管理
export const attendanceTableColumn = [
  {
    name: "员工编号",
    value: "workCode",
  },
  {
    name: "姓名",
    value: "userName",
  },
  {
    name: "岗位名称",
    value: "positionName",
  },
  {
    name: "一级部门",
    value: "deptNameT1",
    width: '120px'
  },
  {
    name: "二级部门",
    value: "deptNameT2",
    width: '120px'
  },
  {
    name: "三级部门",
    value: "deptNameT3",
    width: '120px'
  },
  {
    name: "四级部门",
    value: "deptNameT4",
  },
  {
    name: "五级部门",
    value: "deptNameT5",
  },
  {
    name: "外包人员汇报对象",
    value: "manager",
    width: "140px",
  },
  {
    name: "月份",
    value: "attendanceDate",
  },
  {
    name: "工时（小时）",
    value: "workDay",
    width: '110px'
  },
  {
    name: '操作',
    type: "operate",
    width: "80px",
    fixed: "right",
    render: (h, {row, listeners}) => {
      return h('span', {
        class: `cursor table-btn table-blue-btn`,
        on: {
          click:function(){
            listeners.click('onLookDetail')
          }
        }
      }, '查看')
    }
  }
]

// * 考勤管理详情
export const attendanceDetailTableColumn = [
  {
    name: '工号',
    value: 'workCode'
  },
  {
    name: "姓名",
    value: 'userName'
  },
  {
    name: "考勤日期",
    value: 'attendanceDate',
    width: '100px'
  },
  {
    name: "应出勤时间（小时）",
    value: 'shouldAttendanceTime'
  },
  {
    name: "实际出勤时间（小时）",
    value: "realAttendanceTime",
  },
  {
    name: "当日迟到（分钟）",
    value: "lateTime",
  },
  {
    name: "当日早退（分钟）",
    value: "earlyLeaveTime",
  },
  {
    name: "旷工时间（小时）",
    value: "absenceTime",
  },
  {
    name: "出差时间（小时）",
    value: "travelTime",
  },
  {
    name: "外出时间（小时）",
    value: "outTime",
  },
  {
    name: "加班时间（小时）",
    value: "overtime",
  },
  {
    name: "请假时间（小时）",
    value: "vacateTime",
  },
]
